package com.littleu.yojoincn.controller.tt;

import com.littleu.yojoincn.dto.celebrity.AddressDTO;
import com.littleu.yojoincn.model.CelebrityAddressDO;
import com.littleu.yojoincn.service.CelebrityService;
import com.littleu.yojoincn.vo.CreatedVO;
import com.littleu.yojoincn.vo.UpdatedVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Positive;
import java.util.List;

@RestController
@Validated
@RequestMapping("/tt/celebrity")
public class CelebrityController {
    @Autowired
    private CelebrityService celebrityService;

    @GetMapping("/{id}/address")
    public List<CelebrityAddressDO> getAddressList(@PathVariable @Positive Long id){
        return this.celebrityService.getCelebrityAddressList(id);
    }

    @GetMapping("/{id}/address/default")
    public CelebrityAddressDO getDefaultAddress(@PathVariable @Positive Long id){
        return this.celebrityService.getCelebrityDefaultAddress(id);
    }

    @PostMapping("/{id}/address/default/{aid}")
    public CreatedVO setAddressDefault(@PathVariable @Positive Long id, @PathVariable @Positive Long aid){
        this.celebrityService.setCelebrityAddressDefault(id, aid);
        return new CreatedVO(1);
    }

    @PostMapping("/{id}/address")
    public CreatedVO createAddress(@RequestBody @Validated AddressDTO dto, @PathVariable @Positive Long id){
        dto.setCelebrityId(id);
        this.celebrityService.createCelebrityAddress(dto);
        return new CreatedVO(1);
    }

    @PutMapping("/{id}/address/{aid}")
    public UpdatedVO updateAddress(@RequestBody @Validated AddressDTO dto, @PathVariable @Positive Long id, @PathVariable @Positive Long aid){
        dto.setCelebrityId(id);
        this.celebrityService.updateCelebrityAddress(aid, dto);
        return new UpdatedVO(2);
    }

    @DeleteMapping("/address/{aid}")
    public void deleteAddress(@PathVariable @Positive Long aid){
        this.celebrityService.deleteCelebrityAddress(aid);
    }
}
